﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Transactions;
using IssueTracker.Data;
using IssueTracker.Business.Entity;

namespace IssueTracker.Business.BO
{
    public class ProjectCustomTypeColumnBO
    {
        
  
        private ProjectCustomTypeColumnDataAccess da;

        public ProjectCustomTypeColumnBO() 
        {
            da = new ProjectCustomTypeColumnDataAccess();
        }


#region Business Methods

        /// <summary>
        /// Add a new ProjectCustomTypeColumn
        /// </summary>
        /// <param name="projectCustomTypeColumn"></param>
        /// <returns></returns>
        public ProjectCustomTypeColumn AddNew(ProjectCustomTypeColumn projectCustomTypeColumn)
        {
            ProjectCustomTypeColumn returnProjectCustomTypeColumn;

            projectCustomTypeColumn.CreationDate = DateTime.Today.Date;

            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    returnProjectCustomTypeColumn = da.Create(projectCustomTypeColumn);
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                
            }

            return returnProjectCustomTypeColumn;

        }

        public ProjectCustomTypeColumn UpdateProjectCustomTypeColumn(ProjectCustomTypeColumn projectCustomTypeColumn)
        {
            ProjectCustomTypeColumn returnProjectCustomTypeColumn;

            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    returnProjectCustomTypeColumn = da.Update(projectCustomTypeColumn);
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                
                return returnProjectCustomTypeColumn;
            }
        }

        public void DeleteProjectCustomTypeColumn(ProjectCustomTypeColumn projectCustomTypeColumn)
        {
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    da.Delete(projectCustomTypeColumn);
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

        public IEnumerable<ProjectCustomTypeColumn> ListProjectCustomTypeColumns()
        {
            ProjectCustomTypeColumnDataAccess data = new ProjectCustomTypeColumnDataAccess();

            IEnumerable<ProjectCustomTypeColumn> returnList = data.List();
            return returnList;
        }

        public ProjectCustomTypeColumn GetProjectCustomTypeColumn(int id)
        {
            return da.Retrieve(id);
        }

        public IEnumerable<ProjectCustomTypeColumn> ListProjectCustomTypeColumnsByRef(int reference)
        {
            return da.ListByReferenceId(reference);
        }
        
#endregion
        
   
    }
}
